package cn.tedu.carehome.foundation.service.impl;

import cn.tedu.carehome.foundation.ex.ServiceException;
import cn.tedu.carehome.foundation.mapper.*;
import cn.tedu.carehome.foundation.pojo.dto.BedAddNewDTO;
import cn.tedu.carehome.foundation.pojo.dto.BedUpdateDTO;
import cn.tedu.carehome.foundation.pojo.entity.Bed;
import cn.tedu.carehome.foundation.pojo.entity.Room;
import cn.tedu.carehome.foundation.pojo.vo.*;
import cn.tedu.carehome.foundation.service.IBedService;
import cn.tedu.carehome.foundation.service.IFinanceService;
import cn.tedu.carehome.foundation.web.ServiceCode;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.List;

@Service
@Slf4j
public  class FinanceServiceImpl implements IFinanceService {
    @Autowired
    FinanceMapper financeMapper;
    @Override
    public List<FinanceListItemVO> list() {
        List<FinanceListItemVO> list = financeMapper.seletFinanceList();
        for(FinanceListItemVO item:list){
            //计算每年的食品费用
            BigDecimal foodCost=item.getFoodCost();
            BigDecimal dayToYear = new BigDecimal("365");
            BigDecimal foodCostByYear = foodCost.multiply(dayToYear);
            item.setFoodCostByYear(foodCostByYear);


            //计算每年床位费
            BigDecimal bedCost=item.getBedCost();
            BigDecimal monthToYear=new BigDecimal("12");
            BigDecimal bedCostByYear=bedCost.multiply(monthToYear);
            item.setBedCostByYear(bedCostByYear);

            //计算每年基础费
            BigDecimal sumCost = foodCostByYear.add(bedCostByYear);
            item.setSumCost(sumCost);


            //计算每年服务费
            BigDecimal serviceLow=new BigDecimal("1000");//最低服务费
            BigDecimal i = new BigDecimal("0.1");//服务费比例
            BigDecimal serviceCost = sumCost.multiply(i).add(serviceLow);
            item.setServiceCost(serviceCost);


            //计算总费用
            BigDecimal totalCost = sumCost.add(serviceCost);
            item.setTotalCost(totalCost);
        }
        return list;
    }
}
